package com.eleadin.ruleengine.easyrules.enums;

/**
 * @descriptions:
 * @author:
 * @date: 2023/8/10
 */
public enum EasyRulesOperation {
    GREATER_THAN("GREATER_THAN", "%s > %s", "大于"),
    GREATER_THAN_EQUAL("GREATER_THAN_EQUAL", "%s >= %s", "大于等于"),
    LESS_THAN("LESS_THAN", "%s < %s", "小于"),
    LESS_THAN_EQUAL("LESS_THAN_EQUAL", "%s <= %s", "小于等于"),
    EQUAL("EQUAL", "%s == %s", "等于"),
    UNEQUAL("UNEQUAL", "%s != %s", "不等于"),
    BETWEEN("BETWEEN", "%s >= %s && %s <= %s", "介于之间"),
    OUT_OF_RANGE("OUT_OF_RANGE", "%s >= %s || %s >= %s", "超出范围"),
    CONTAINS("CONTAINS", "%s.contains(\"%s\")", "包含"),
    STARTS_WITH("STARTS_WITH", "%s.startsWith(\"%s\")", "前缀"),
    ENDS_WITH("ENDS_WITH", "%s.endsWith(\"%s\")", "后缀"),
    ;

    public static EasyRulesOperation getOperationByOperator(String operator) {
        EasyRulesOperation[] list = EasyRulesOperation.values();
        for (EasyRulesOperation item : list) {
            String compareOperator = item.getOperator();
            if (compareOperator.equals(operator)) {
                return item;
            }
        }
        return null;
    }

    private final String operator;
    private final String expression;
    private final String remark;

    EasyRulesOperation(String operator, String expression, String remark) {
        this.operator = operator;
        this.expression = expression;
        this.remark = remark;
    }

    public String getOperator() {
        return operator;
    }

    public String getExpression() {
        return expression;
    }

    public String getRemark() {
        return remark;
    }
}
